package com.stox.shared.i18n;

import java.util.MissingResourceException;
import java.util.ResourceBundle;
/**
 * 
 * Below are reasons to add this class
 * 1. Application compenents must not be aware of spring framework explicitly. Thus this is a wrapper class.
 * 2. As we are using spring-emulation anyway, thus not using spring specific classes
 * 3. If using actual spring, still these methods must be static.
 *
 */
public class MessageSource {
	
	private static ResourceBundle resourceBundle = ResourceBundle.getBundle("i18n.messages");
	
	public static String get(String key){
		if(null == key){
			return key;
		}
		try{
			return resourceBundle.getString(key);
		}catch(MissingResourceException e){
			return key;
		}
	}
	
	/**
	 * Remember to call Locale.setDefault before calling this method, for change to take place
	 */
	public static void refresh(){
		resourceBundle = ResourceBundle.getBundle("i18n.messages");
	}
}
